package com.shinhye.elephantsafe;

import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class GuardSetup3Activity extends GuardSetupBaseActivity {
	private EditText et_safephone;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide3);
		
		et_safephone = (EditText) findViewById(R.id.et_guide_safephone);
		String safephone = getSP().getString("safephone", "");
		et_safephone.setText(safephone);
	}

	@Override
	public void showNext() {
		String safephone = et_safephone.getText().toString();
		if(TextUtils.isEmpty(safephone)) {
			Toast.makeText(this, "请设置安全号码！", Toast.LENGTH_SHORT).show();
			return;
		}
		Editor editor = getSP().edit();
		editor.putString("safephone", safephone);
		editor.commit();
		
		Intent intent = new Intent(this, GuardSetup4Activity.class);
		startActivity(intent);
		finish();
		overridePendingTransition(R.anim.translate_next_in, R.anim.translate_next_out);
	}

	@Override
	public void showPrev() {
		Intent intent = new Intent(this, GuardSetup2Activity.class);
		startActivity(intent);
		finish();
		overridePendingTransition(R.anim.translate_prev_in, R.anim.translate_prev_out);
	}
	
	public void selectcontact(View v) {
		Intent intent = new Intent(this, SelectContactActivity.class);
		startActivityForResult(intent, 101);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(requestCode == 101) {
			if(resultCode == RESULT_OK) {
				String text = data.getStringExtra("number");
				String number = text.replace("-", "").replace(" ", "");
				et_safephone.setText(number);
			}
		}
	}
}
